var guidEmpty = "00000000-0000-0000-0000-000000000000";
var PAGINATION_HEIGHT = 32; //分页控件高度
var app;
/**
 * API Host地址
 */

var API_DOWNLOAD_PATH = "/api/file/DownLoad"; //文件下载API路径
var API_UPLOADFILE_PATH = "/api/File/UploadFile"; //文件上传API路径
var API_PPT_UPLOADFILE_PATH = "/api/File/UploadPPT"; //PPT文件上传API路径


/**
 * //上传 下载APIURL
 */
var API_DOWNLOAD_URL = host + API_DOWNLOAD_PATH;
var API_UPLOADFILE_URL = host + API_UPLOADFILE_PATH;

/**
 * 生成文件下载地址
 * @param {*} fileId 文件ID
 */
function downLoadUrl(fileId) {
    return API_DOWNLOAD_URL + "?id=" + fileId;
}


/**
 * 生成文件下载路径
 * @param {*} fileId 
 */
function downLoadPath(fileId) {
    return API_DOWNLOAD_PATH + "?id=" + fileId;
}

//生成GUID
function newGuid() {
    var guid = "";
    for (var i = 1; i <= 32; i++) {
        var n = Math.floor(Math.random() * 16.0).toString(16);
        guid += n;
        if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
            guid += "-";
    }
    return guid;
}

//Ajax 授权/认证失败后处理
$(function () {

    $(document).ajaxComplete(function (event, request, settings) {


        if (request.status === 401) { //Unauthorized
            showMessage("您登录授权已经超时！", "error");

            var timeout = setTimeout(function () {
                window.location.href = "login.html";
            }, 2000);

        }
        if (request.status === 403) {
            showMessage("您没有此功能的访问权限！", "error");
        }



    })

});
//获取表单内容
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg); //匹配目标参数
    if (r != null) return unescape(r[2]);
    return null; //返回参数值
}
//设置列表页面table高度：注册 20190613
function tablehigh(mythis) {
    setTableHigh(mythis);
    setPageHeight();
    window.onresize = function () {
        setTableHigh(mythis);
    }
}
//设置列表页面table高度 
//2019-6-13 13:27:44  
//houts 2019-10-23 15:37:50  修复无table页面异常报错
function setTableHigh(mythis) {
    mythis.$nextTick(function () {
        var margin = 0;
        if ($("#app > .el-row:first-child").length > 0)
            margin = 8;

        var offsetTop = 0;
        if (mythis.$refs && mythis.$refs.table && mythis.$refs.table.$el)
            offsetTop = mythis.$refs.table.$el.offsetTop;
        if (mythis && mythis.ListItem)
            mythis.ListItem.tableHeight = window.innerHeight -
                offsetTop - PAGINATION_HEIGHT - margin;
    })

}

function setPageHeight() {
    var $ = window.top.$;
    var tabsContentH = $(".el-main").height() - 44; //el-tabs__header高度为41 外部el-main有padding 3  41+3=44
    $(".el-tabs").height($(".el-main").height()) //这里需要重新设置下 tabs整体高度，不知道为什么有些页面计算完莫名高出main div所以重新设置下tabs高度
    $(".el-tabs__content").height(tabsContentH)
    $(".el-tab-pane").height(tabsContentH);
}

//List页面公共属性
var myloading = {
    lock: true,
    text: '操作中...',
    spinner: 'el-icon-loading',
    background: 'rgba(0, 0, 0, 0.7)',
    target: document.querySelector('.submit-test-dialog')
}

//List页面公共属性
var ListItem = {
    type: 'tj',

    loadingbut: false,
    //列表选择数组
    tableMultipleSelection: [],
    //分页
    pagesizes: [5, 10, 40],
    //分页控件显示内容
    layout: '  prev, pager, next,sizes,total',
    //一页数量
    pagesize: 10,
    //数据总量
    total: 0,
    //dialog src值
    InputUrl: '',
    //当前页码
    currentPage: 1,
    //dialog是否展示
    dialogVisible: false,
    //表格高度
    tableHeight: 200,
    //列表数据
    tableData: [],
    //数据源
    dataSource: [],
    //行内编辑时的临时行显示对象
    modityShowRow: {},
    //行内编辑时的临时行数据对象
    modityDataRow: {},
}
//List删除方法
function onDelete(mythis, url) {
    if (mythis.ListItem.tableMultipleSelection.length == 0) {
        showMessage(msg.AtLeastOne, 'error')
        return;
    }

    mythis.$confirm(' 是否确认继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(function () {
        //console.log(123)
        var delIds = [];
        for (var i = 0; i < mythis.ListItem.tableMultipleSelection.length; i++) {
            var item = mythis.ListItem.tableMultipleSelection[i];
            delIds.push(item.id);
        }
        myAjax("post", mythis, url, delIds, function (response) {
            mythis.GetPageData(1);
            mythis.ListItem.currentPage = 1;
            showMessage(msg.OperatingOk, "success");
        });
    }).catch(function () {
        showMessage("已取消删除!");
    });

}

//List删除方法)(没有分页的列表删除)
function onDeleteA(mythis, url) {
    if (mythis.ListItem.tableMultipleSelection.length == 0) {

        showMessage(msg.AtLeastOne, 'error')
        return;
    }
    mythis.$confirm(' 是否确认继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(function () {
        var delIds = [];
        for (var i = 0; i < mythis.ListItem.tableMultipleSelection.length; i++) {
            var item = mythis.ListItem.tableMultipleSelection[i];
            delIds.push(item.id);
        }
        var temp = [];
        for (var i = 0; i < mythis.mydata.length; i++) {
            temp.push(mythis.mydata[i]);
        }
        for (var i = 0; i < temp.length; i++) {
            if (delIds.includes(temp[i].id)) {
                mythis.mydata.splice(i, 1);
            }
        }
        mythis.TreeTable = fn1(mythis.mydata, "0");
        showMessage(msg.OperatingOk, "success");

    }).catch(function () {
        showMessage("已取消删除!");
    });

}
//
function dianX(row, tableList) {
    if (this.ListItem.type == 'xg') {
        var mythis = this;
        for (var key in row) {
            row[key] = mythis.ListItem.modityShowRow[key]
        }
    } else {
        tableList.splice(0, 1);

    }
}

//Dialog展示
function DialogShow(mythis, val, url, id, urlParam) {
    var urlParamStr = urlParam ? "&" + urlParam : "";
    if (val == 'tj') {
        mythis.ListItem.InputUrl = url + "?t=" + Date.parse(new Date()) + urlParamStr;
    } else {
        mythis.ListItem.InputUrl = url + "?id=" + id + "&t=" + Date.parse(new Date()) + urlParamStr;
    }
    mythis.ListItem.dialogVisible = true;
    //解决弹窗底下按钮显示不全
    setTimeout(function () {
        // alert($('.el-dialog__body').height())
        var bodyH = $('.el-dialog__body').height()
        $('.el-dialog__body').children('iframe').height(bodyH - 50)
        // alert($('.el-dialog__body').children('iframe').height())
    }, 100);
}
//Dialog展示--权限传值
function DialogPowerShow(mythis, val, url, id) {
    if (val == 'tj') {
        var powerid = "tj";
        mythis.ListItem.InputUrl = url + "?t=" + powerid;
    } else if (val == 'xg') {
        var powerid = "xg";
        mythis.ListItem.InputUrl = url + "?id=" + id + "&t=" + powerid;
    } else if (val == 'sh') {
        var powerid = "sh";
        mythis.ListItem.InputUrl = url + "?id=" + id + "&t=" + powerid;
        //var powerid = Date.parse(new Date());
    } else if (val == 'pz') {
        var powerid = "pz";
        mythis.ListItem.InputUrl = url + "?id=" + id + "&t=" + powerid;
    }
    mythis.ListItem.dialogVisible = true;
    //解决弹窗底下按钮显示不全
    setTimeout(function () {
        // alert($('.el-dialog__body').height())
        var bodyH = $('.el-dialog__body').height()
        $('.el-dialog__body').children('iframe').height(bodyH - 50)
        // alert($('.el-dialog__body').children('iframe').height())
    }, 100);
}

//帮助列表checkbox翻页记忆
function getRowKeys(row) {

    return row.id;
}

//List关闭Dialog 回调
function closeDialog() {

    app.ListItem.currentPage = 1;
    app.GetPageData(1);
}
//列表选择触发
function handleSelectionChange(mythis, val) {
    console.log(val)
    mythis.ListItem.tableMultipleSelection = val;
}
//获取分页数据
function GetPageData(mythis, currentIndex, url) {
    mythis.formInline.offset = (currentIndex - 1) * mythis.ListItem.pagesize;
    mythis.formInline.limit = mythis.ListItem.pagesize;
    var currObj = mythis;
    myAjax("post", mythis, url, mythis.formInline, function (response) {
        console.log(response);
        currObj.ListItem.tableData = response.data.pageData
        currObj.ListItem.total = response.data.rowCount;

    });

}
//单页数据--不支持分页
function GetOnePageData(mythis, currentIndex, url) {
    var currObj = mythis;
    myAjax("post", mythis, url, mythis.formInline, function (response) {
        console.log(response);
        currObj.ListItem.tableData = response.data.pageData
        currObj.ListItem.total = response.data.rowCount;

    });

}
//查询方法
function onSubmit(mythis) {
    mythis.ListItem.currentPage = 1;
    mythis.GetPageData(1);
}
//pagesize改变 触发方法
function handleSizeChange(mythis, val) {
    mythis.ListItem.pagesize = val;
    mythis.GetPageData(1);

}
//跳页触发方法
function handleCurrentChange(mythis, val) {
    mythis.ListItem.currentPage = val;
    mythis.GetPageData(val);
}
//input提交数据
function onSubmitForm(mythis, url, Form) {
    var mythis = mythis;
    var loadingObj;
    if (mythis._isVue)
        loadingObj = mythis.$loading(myloading);
    else
        loadingObj = mythis.app.$loading(myloading);
    mythis.ListItem.loadingbut = true;

    myAjax("post", mythis, url, Form, function (response) {
        showMessage(msg.OperatingOk, 'success');
        parent.app.ListItem.dialogVisible = false;

        mythis.ListItem.loadingbut = false;
        //mythis.submit = true;
        loadingObj.close();
    }, false, function (response) {
        showMessage(response.message, 'error')
        loadingObj.close();

    });
}
//input提交数据--不弹窗
function onSubmitNoWindowsForm(mythis, url, Form) {
    var mythis = mythis;
    myAjax("post", mythis, url, Form, function (response) {
        showMessage(msg.OperatingOk, 'success');
        //parent.app.ListItem.dialogVisible = false;
    });
}
//input获取数据
function getData(mythis, url) {
    var mythis = mythis;
    if (mythis.id != null && mythis.id != '') {
        myAjax("get", mythis, url, null, function (response) {
            var ajaxModel = response.data;

            mythis.Form = ajaxModel;
            //mythis.userFrom.sex = mythis.userFrom.sex + "";
        }, false);
    }
}

function getDataAdd(mythis, url) {
    var mythis = mythis;
    myAjax("get", mythis, url, null, function (response) {
        var ajaxModel = response.data;
        mythis.Form = ajaxModel;
        //mythis.userFrom.sex = mythis.userFrom.sex + "";
    }, false);
}


function getDataRish(mythis, url) {
    var mythis = mythis;
    myAjax("getRish", mythis, url, null, function (response) {
        var ajaxModel = response.data;
        mythis.Form = ajaxModel;
        //mythis.userFrom.sex = mythis.userFrom.sex + "";
    }, false);
}

//字符串 数组format的方法
String.prototype.format = function (v) {
    v = typeof v === 'object' ? v : Array.prototype.slice.call(arguments);
    return this.replace(/\{\{|\}\}|\{(\w+)\}/g, function (m, n) {
        if (m == "{{") return "{";
        if (m == "}}") return "}";
        return v[n] == null ? "" : v[n];
    });
}

//顶级弹窗
function showMessage(message, type) {


    var topWin = window.top;
    if (type == null) {
        topWin.app.$message({
            type: 'info',
            duration: 3000,
            offset: 10,
            message: message
        });
    }
    if (type == "error") {
        topWin.app.$message({
            type: 'error',
            duration: 3000,
            offset: 10,
            message: message
        });
    }
    if (type == "success") {
        topWin.app.$message({
            type: 'success',
            duration: 3000,
            offset: 10,
            message: message,
        });
    }
}

//判断Ajax业务是否处理成功
function isSuccess(ajaxModel) {
    return ajaxModel.result == "Success"
}


//function myAjax(type, vueApp, url, data, succFun, isasync, errorFun) {
//    if (isasync != false) {
//        isasync = true;
//    }

//    var obj = {}
//    if (data == null) {
//        obj = {
//            type: type,
//            dataType: "json",
//            contentType: 'application/json;charset=utf-8',
//            async: isasync,
//            url: host + url,
//            success: function (response) {
//                if (isSuccess(response)) {
//                    if (succFun)
//                        succFun(response);
//                } else {
//                    if (!errorFun)
//                        showMessage(response.message, 'error')
//                    else
//                        errorFun(response);
//                }
//            },
//            xhrFields: {
//                withCredentials: true // 此字段标识要跨域传数据
//            },
//            crossDomain: true
//        };

//    } else {

//        obj = {
//            type: type,
//            dataType: "json",
//            contentType: 'application/json;charset=utf-8',
//            async: isasync,
//            url: host + url,
//            data: JSON.stringify(data),
//            success: function (response) {
//                if (isSuccess(response)) {

//                    if (succFun)
//                        succFun(response);
//                } else {
//                    if (!errorFun)
//                        showMessage(response.message, 'error')
//                    else
//                        errorFun(response);
//                }

//            },
//            xhrFields: {
//                withCredentials: true // 此字段标识要跨域传数据
//            },
//            crossDomain: true
//        };
//    }
//    $.ajax(obj);
//};

function myAjax(type, vueApp, url, data, succFun, isasync, errorFun) {
    if (isasync != false) {
        isasync = true;
    }

    var obj = {}
    //if (data == null) {
    //    obj = {
    //        type: type,
    //        dataType: "json",
    //        contentType: 'application/json;charset=utf-8',
    //        async: isasync,
    //        url: host + url,
    //        success: function (response) {
    //            if (isSuccess(response)) {
    //                if (succFun)
    //                    succFun(response);
    //            } else {

    //                if (!errorFun)
    //                    showMessage(response.message, 'error')
    //                else
    //                    errorFun(response);
    //            }
    //        },

    //        xhrFields: {
    //            withCredentials: true // 此字段标识要跨域传数据
    //        },
    //        crossDomain: true
    //    };

    //} else {

    obj = {
        type: type,
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        async: isasync,
        url: host + url,
        data: data == null ? null : JSON.stringify(data),
        success: function (response) {

            if (isSuccess(response)) {

                if (succFun)
                    succFun(response);
            } else {
                if (!errorFun)
                    showMessage(response.message, 'error')
                else
                    errorFun(response);
            }

        },
        error: function (response) {

            var loadingObj;
            if (vueApp && vueApp.ListItem && vueApp.ListItem.loadingbut) {
                if (vueApp._isVue)
                    loadingObj = vueApp.$loading(myloading);
                else
                    loadingObj = vueApp.app.$loading(myloading);
                vueApp.ListItem.loadingbut = false;

                loadingObj.close();
            }

        },
        xhrFields: {
            withCredentials: true // 此字段标识要跨域传数据
        },
        crossDomain: true
    };
    //}
    obj.complete = function (request, textStatus) {

        //console.log("request", request);
        if (request.status === 401) { //Unauthorized
            showMessage("您登录授权已经超时！", "error");

            var timeout = setTimeout(function () {
                window.top.location.href = "/login.html";
            }, 2000);

        }
        if (request.status === 403) {
            showMessage("您没有此功能的访问权限！", "error");
        }
    }

    $.ajax(obj);
};

//扁平化数据处理成树形数据
function fn(data, pid) {

    var result = [],
        temp;
    for (var i = 0; i < data.length; i++) {
        if (data[i].pid == pid) {
            var obj = {
                "label": data[i].name,
                "id": data[i].id,
                "icon": 'tree-item'
            };
            temp = this.fn(data, data[i].id);
            if (temp.length > 0) {
                obj.children = temp;
                obj.icon = 'tree-open';
            }
            result.push(obj);
        }
    }
    console.log(result)
    return result;
}


//扁平化数据处理成树形数据
function fn1(data, pid) {
    var result = [],
        temp;
    for (var i = 0; i < data.length; i++) {
        if (data[i].pid == pid) {
            var obj = {
                "id": data[i].id,
                "ProductionActivityName": data[i].name,
                "Code": data[i].code,
                "remarks": data[i].remarks,
                "icon": 'tree-item'
            };
            temp = this.fn1(data, data[i].id);
            if (temp.length > 0) {
                obj.children = temp;
                obj.icon = 'tree-open';
            }
            result.push(obj);
        }
    }
    return result;
}

//扁平化数据处理成树形数据
function fnCommon(data, pid) {
    var result = [],
        temp;
    data.forEach(function (v, i) {
        if (v.pid == pid) {
            var obj = {};
            for (var key in v) {
                obj[key] = v[key];
            }
            obj.icon = 'tree-item';
            temp = this.fnCommon(data, data[i].id);
            if (temp.length > 0) {
                obj.children = temp;
                obj.icon = 'tree-open';
            }
            result.push(obj);
        }
    })
    return result
}

//附件上传统一处理
function submitUpload(mythis, url) {
    myAjax("post", this, url, null,
        function (response) {
            console.log(response.message)
            showMessage(response.message, 'success')
        });

}

function GetQueryString(url, name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}



/**
 * //根据categoryCode数组 获取data数组 
 * @param {*} categoryCodeList 
 */
function getDicDataArray(categoryCodeList) {
    var data = [];

    var url = "/api/DataDir/GetDicValue?";
    categoryCodeList.forEach(function (v) {
        var item = "categoryCodArray=" + v + "&";
        url += item;
    });

    myAjax("get", this, url, null, function (response) {
        data = response.data;
    }, false);
    return data;
}


/**
 * //根据categoryCode 获取data 
 * @param {*} categoryCode
 */
function getDicData(categoryCode) {
    var dataList = getDicDataArray([categoryCode])
    return dataList[0].value;
}

/**
 * 根据已有数组，获取指定code数据
 * @param {已有数组} datalist 
 * @param {字典的category} categoryCode
 */
function getDicDataFodDataList(datalist, categoryCode) {
    var dataItem = {};
    datalist.forEach(function (item) {
        if (item.key == categoryCode) {
            dataItem = item;
            return;
        }
    });
    return dataItem.value;
}


/**
 * 根据字典categoryCode集合以及FunctionCode集合返回信息
 * @param {*} categoryCodeArray 
 * @param {*} FunctionCodeArray 
 */
function PageInitial(categoryCodeArray, FunctionCodeArray, isGetFactoryList, isGetFactoryListAll) {
    var data = {
        CategoryCodeArray: categoryCodeArray,
        FunctionCodeArray: FunctionCodeArray,
        IsGetFactoryList: isGetFactoryList,
        isGetFactoryListAll: isGetFactoryListAll
    };
    var url = "/api/WebPageInitial/PageInitial";

    myAjax("Post", this, url, data, function (response) {
        data = response.data;
    }, false);
    return data;
}

/**
 * 传入PageInitial的权限集合，根据该集合查询指定functionCode 的value值（是否有权限）
 * @param {*} functionCodeList 
 * @param {*} functionCode 
 */
function authorize(functionCodeList, functionCode) {
    if (functionCodeList)
        for (var i = 0; i < functionCodeList.length; i++)
            if (functionCodeList[i].key == functionCode)
                return functionCodeList[i].value;
    return false;
}
/**
 * 获取区域数据
 * @param {any} vueObj
 * //注意：后台约束空值为null  但是Tree id =null时有bug体现在setCheckedKeys 
 * 所以只能在扁平化上处理为guidempty，在传给后台前在做处理
 * 
 * Tree.Js已调用次方法
 */
function GetAreaTreeData(vueObj, factoryId) {
    var mythis = vueObj;
    var treeAreaData;
    myAjax("post", vueObj, '/api/SysArea/GetList', { offset: 0, limit: 999, model: { SubFactory: factoryId } }, function (response) {
        var dataSource = response.data.pageData;
        var data = MenuHelper(dataSource, guidEmpty);
        data.unshift({ id: guidEmpty, label: '全部', Id: guidEmpty })//初始化无父级的选项
        treeAreaData = data;
    }, false);
    return treeAreaData;
}

/**
 * 区域数据扁平化处理
 * @param {any} list
 * @param {any} pid
 */
function MenuHelper(list, pid) {
    var result = [];
    list.forEach(function (v, i) {
        if (!v.parentId) v.parentId = guidEmpty;
        if (v.parentId == pid) {
            var obj = {};
            obj.id = v.id + '';
            obj.label = v.name + '';
            obj.icon = 'tree-item';
            var nextObj = MenuHelper(list, v.id);
            if (nextObj.length > 0) {
                obj.children = nextObj;
                obj.icon = 'tree-open';
            }
        }
        if (obj)
            result.push(obj)
    })
    return result;
}

/**
 * 部门数据扁平化处理
 * @param {any} list
 * @param {any} pid
 */
function departmentHelper(list, pid) {
    var result = [];

    list.forEach(function (v, i) {
        if (!v.parentId) v.parentId = null;
        if (v.parentId == pid) {
            var obj = {};
            obj.id = v.id + '';
            obj.label = v.name + '';
            var nextObj = departmentHelper(list, v.id);
            if (nextObj.length > 0) {
                obj.children = nextObj;
            }
        }
        if (obj)
            result.push(obj)
    })
    return result;
}
//人员扁平
function PersonMenuHelper(list, pid) {
    var result = [];
    if (list.length <= 0)
        return list;
    list.forEach(function (v, i) {
        var temp = {};
        for (var key in v) {
            temp[key] = v[key];
        }
        //temp.label = v.name;
        temp.parentId = temp.parentId ? temp.parentId : guidEmpty;
        var obj;
        if (temp.parentId == pid) {
            obj = temp;
            var nextObj = PersonMenuHelper(list, temp.id);
            if (nextObj.length > 0) {
                obj.children = nextObj;
            }
        }
        if (obj) {
            //过滤掉没有人员的部门，obj.t=0是部门，obj.t=1是人员
            if ((obj.t == 0 && obj.children) || obj.t == 1) {
                result.push(obj)
            }
        }
    })
    return result;
}
//格式化日期
function myformatDate(row, col, cellValue) {

    var time = cellValue;
    if (time) {
        var oldTime = new Date(time.replace(/-/g, "/"));
        return oldTime.getFullYear() + "-" + (oldTime.getMonth() + 1) + "-" + oldTime.getDate();
    }
    return "";
}


function DeleteQueryResult(mythis, count, deleteQueryResultUrl) {
    var selectCount = count;
    mythis.$confirm('删除当前查询内容,共' + selectCount + '条?', '重要提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(function () {
        myAjax("post", mythis, deleteQueryResultUrl, mythis.formInline, function (response) {
            mythis.GetPageData(1);
            showMessage("删除成功", "success");
        }, false);
    }).catch(function () {
        showMessage("已取消删除!");
    });

}


var pickerOptions = {
    shortcuts: [{
        text: '今天',
        onClick: function (picker) {
            picker.$emit('pick', new Date());
        }
    }, {
        text: '昨天',
        onClick: function (picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
        }
    }, {
        text: '一周前',
        onClick: function (picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
        }
    }]
};


//解決edge下select bug
function visibleChange(isVisible) {
    // alert()
    const isEdge = window.navigator.userAgent.includes('Edge');
    if (isEdge && !isVisible) {
        document
            .querySelectorAll('body > .el-select-dropdown.el-popper')
            // .forEach((it) => it.remove());
            .forEach(function (it) { it.remove() });
    }
};